#include <bits/stdc++.h>
using namespace std;

vector<int> scores = {25, 18, 15, 12, 10, 8, 6, 4, 2, 1};

struct Driver {
    string name;
    int score = 0;
    vector<int> positions;

    Driver() : positions(101, 0){}
};

int main(){
    int n;
    unordered_map<string, Driver> driver;
    cin >> n;
    while(n--){
        int m;
        cin >> m;
        for(int i = 0; i < m; ++i){
            string name;
            cin >> name;
            if(driver.find(name) == driver.end()){
                driver[name].name = name;
                driver[name] = Driver();
            }
            int add;
            if(i > 9) add = 0;
            else add = scores[i];
            driver[name].score += add;
            driver[name].positions[i]++;
        }
    }
    auto cmp1 = [&](string a, string b){
        if(driver[a].score != driver[b].score){
            return driver[a].score > driver[b].score;
        }

        for(int i = 0; i < 101 ; ++i){
            if(driver[a].positions[i] != driver[b].positions[i]){
                return driver[a].positions[i] > driver[b].positions[i];
            }
        }
        return true;
    };
    auto cmp2 = [&](string a, string b){
        if(driver[a].positions[0] != driver[b].positions[0]){
            return driver[a].positions[0] > driver[b].positions[0];
        }

        if(driver[a].score != driver[b].score){
            return driver[a].score > driver[b].score;
        }

        for(int i = 1; i < 101 ; ++i){
            if(driver[a].positions[i] != driver[b].positions[i]){
                return driver[a].positions[i] > driver[b].positions[i];
            }
        }
        return true;
    };

    vector<string> allname;
    for(auto &[str, s] : driver){
        allname.push_back(str);
    }

    sort(allname.begin(), allname.end(), cmp1);
    cout << allname[0] << endl;
    sort(allname.begin(), allname.end(), cmp2);
    cout << allname[0] << endl;
    system("pause");
}